<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/inc/common.jsp"%>
<html>
<head>
<title>后台管理</title>
</head>
<body class="easyui-layout">
	<div data-options="region:'center',title:'',footer:'#searchfooter'" >
		<div class="easyui-panel" data-options="region:'north',fit:true,collapsible:true,title:'车辆备案信息'" style="padding:10px 10px 10px 10px;">
	    <form id="editForm"  method="post">
	    	<input type="hidden" name="id" id="id" value="${carArchives.id}">
	    	<input type="hidden" name="serialNo" id="serialNo" value="${carArchives.serialNo}">
	    	<input type="hidden" name="archiveNo" id="archiveNo" value="${carArchives.archiveNo}">
	    	<table  style="width:100%;" cellpadding="0" cellspacing="1"  class="formtable">
				<tr>
					<td align="right" style="width: 10%">流水号:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" value="${carArchives.serialNo}" disabled="disabled">
					</td>
					<td align="right" style="width: 10%">车辆备案号:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" value="${carArchives.archiveNo}" disabled="disabled" >
					</td>
					<td align="right" style="width: 10%">车牌号:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" name="carNo" id="carNo" value="${carArchives.carNo}" data-options="required:true" >
					</td>
		    	</tr>
				<tr>
					<td align="right" style="width: 10%">车辆型号:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" name="carModel" id=carModel value="${carArchives.carModel}"  >
					</td>
					<td align="right" style="width: 10%">车辆颜色:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" name="carColor" id="carColor" value="${carArchives.carColor}"  >
					</td>
					<td align="right" style="width: 10%">发动机号:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" name="engineNo" id="engineNo" value="${carArchives.engineNo}"  >
					</td>
		    	</tr>
				<tr>
					<td align="right" style="width: 10%">底盘号:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" name="chassisNo" id="chassisNo" value="${carArchives.chassisNo}"  >
					</td>
					<td align="right" style="width: 10%">原产国:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" name="originCountry" id="originCountry" value="${carArchives.originCountry}"  >
					</td>
					<td align="right" style="width: 10%">国籍:</td>
					<td class="value">
					<input name="carNationality" id="carNationality" value="${carArchives.carNationality}" >
					</td>					
		    	</tr>
				<tr>
					<td align="right" style="width: 10%">出厂时间:</td>
					<td class="value">
					<input class="easyui-datebox" type="text" id="prodecedTime" name="prodecedTime" value="${prodecedTime}">
					</td>
					<td align="right" style="width: 10%">车主:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" name="carOwner" id="carOwner" value="${carArchives.carOwner}"  >
					</td>
					<td align="right" style="width: 10%">联系电话:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" name="carOwnerTel" id="carOwnerTel" value="${carArchives.carOwnerTel}"  >
					</td>
		    	</tr>
				<tr>
					<td align="right" style="width: 10%">地址:</td>
					<td class="value">
					<input class="easyui-textbox" type="text" name="carOwnerAddress" id="carOwnerAddress" value="${carArchives.carOwnerAddress}"  >
					</td>
					<td align="right" style="width: 10%">生效日期:</td>
					<td class="value">
					<input class="easyui-datebox" type="text" id="beginDate" name="beginDate" value="${beginDate}" data-options="required:true">
					</td>
					<td align="right" style="width: 10%">失效日期:</td>
					<td class="value">
					<input class="easyui-datebox" type="text" id="endDate" name="endDate" value="${endDate}" validType="md['#beginDate']" data-options="required:true">
					</td>
		    	</tr>
				<tr>
					<td align="right" style="width: 10%">车辆类型:</td>
					<td class="value">
					<input name="carUseType" id="carUseType" value="${carArchives.carUseType}"  >
					</td>
					<td colspan="4"></td>
		    	</tr>
	    	</table>
	    </form>
	    <form id="driverForm"  method="post">
	    	<input type="hidden" name="caId" id="caId" value="${carArchives.id}">
		    <table  style="width:100%;" cellpadding="0" cellspacing="1" class="formtable">
				<tr>
					<td align="right" style="width: 10%">护照号:</td>
					<td class="value">
						<input class="easyui-textbox" type="text" name="passportNo" id="passportNo" data-options="required:true">
					</td>
					<td align="right" style="width: 10%">驾驶员姓名:</td>
					<td class="value">
						<input class="easyui-textbox" type="text" name="name" id="name" data-options="required:true">
					</td>
					<td align="right" style="width: 10%">联系电话:</td>
					<td class="value">
						<input class="easyui-textbox" type="text" name="phone" id="phone" data-options="required:true">
					</td>
			    </tr>
			    <tr>
					<td align="right" style="width: 10%">地址:</td>
					<td class="value">
						<input class="easyui-textbox" type="text" name="address" id="address" >
					</td>
					<td colspan="4" style="padding-left: 180px;">
						<a href="javascript:void(0)" class="easyui-linkbutton" onclick="saveDriverDate()"  data-options="iconCls:'icon-page_save',plain:true" >新增</a>
					</td>
			    </tr>
		   </table>
	   </form>
	   	<!-- 数据列表 -->
		<div region="center" split="true" border="false" style="overflow: hidden;width: 100%;height: 180px;">
			<table id="dg"></table>
		</div>
	</div>
	</div>
	<!-- 保存按钮 -->
	<div id="searchfooter" style="text-align:right;padding: 0px 10px">
		<a href="javascript:void(0)" id="submitBtn" class="easyui-linkbutton" onclick="saveDate()"  data-options="iconCls:'icon-page_save',plain:true" >保存</a>
		<span class="search-btn-separator"></span>
		<a href="javascript:history.go(-1)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true">返回</a>
	</div>
</body>
</html>
<script type="text/javascript">
	$(document).ready(function () {	  
		initDg();//初始化datagrid
		//国籍
	    $('#carNationality').combobox({ 
	        url:'${basePath}/sys/dictionary/dicbykey.do?key=1005&type=1',  
	        valueField: 'dataCode',  
	        textField: 'dataName',  
	        editable:false,  
	        panelHeight:'auto',
	        required:true
	    });
		
		//车辆类型
	    $('#carUseType').combobox({ 
	        url:'${basePath}/sys/dictionary/dicbykey.do?key=1009&type=1',  
	        valueField: 'dataCode',  
	        textField: 'dataName',  
	        editable:false,  
	        panelHeight:'auto',
	        required:true
	    });
	});
	
	//回车保存
	$(document).keydown(function(e){
		if(e.keyCode == 13) {
			saveDate();
		}
	});
	
	//防止二次提交
	var submitState = true;
	function saveDate(){
		var isValid = $("#editForm").form('validate');
		if(submitState && isValid){
			submitState = false;
			doSave();
		}
	}
	
	//保存车辆备案
	function doSave(){
		var actionUrl = "";
		var type = '${type}';
		if(type =='1'){
			actionUrl = '${basePath}/bus/carArchives/save.do';
		}else if(type =='2'){
			actionUrl = '${basePath}/bus/carArchives/update.do';
		}
		var record=form2Json('editForm');
		$.ajax({
			type : 'post',
			url :  actionUrl,
			data : "data="+JSON.stringify(record),
			dataType:"json",
			success : function(msg) {
				$.each(msg,function(i,n){
            		if(n.message == "success"){
            			$.messager.alert("消息", "保存成功！");
            			setTimeout(function () {
            				window.location.href="${basePath}/bus/carArchives/index.do";
            			}, 1000);
            		}else{
            			$.messager.alert('消息', n.errMsg);
            		}
               });
			}
		});
	}
	
	//初始化数据列表
	function initDg(){
		$('#dg').datagrid({
			url:'${basePath}/bus/carDriverArchives/query.do?caId=${carArchives.id}',
			loadMsg:'数据装载中......',
		    title:'驾驶员列表',//标题
		    width:'auto',//列表的宽度
			height:'auto',//列表的高度
			fit:true,//自动填充全屏
			nowrap: false,//数据是否显示在一行中
			fitColumns:true,//是否根据字体数收缩
		    pagination:true,//分页底部显示
		    pageList:[10,20,50],//设置分页下拉页数
		    rownumbers : true,//显示行号
			//singleSelect:true,//只能单选
			autoRowHeight:false,//自动行高
		    columns:[[
				{field:'name',title:'姓名',width:fixWidth(20),align:'center'},
				{field:'phone',title:'联系电话',width:fixWidth(20),align:'center'},
				{field:'passportNo',title:'护照号',width:fixWidth(20),align:'center'},
				{field:'address',title:'地址',width:fixWidth(40),align:'center'},
				{field:'id',title:'操作',width:fixWidth(10),align:'center',
					formatter:function(value,row,index){
						return "<a href='javascript:void(0)' onclick=\"delDriverDate('"+value+"')\">删除</a>";
/*						return "<a href='${basePath}/bus/carArchives/cardriverdelete.do?id="+value+"'>删除</a>&nbsp;"; */
					}
				}
			]]
		});
	}
	
	//保存驾驶员
	function saveDriverDate(){
		var actionUrl = "${basePath}/bus/carDriverArchives/save.do";
		$('#driverForm').form('submit', {
		     url:actionUrl,
		     onSubmit: function(){
		    	return $(this).form('validate');
		     },
		     success:function(msg){
	    		 if(msg == "success"){
	    			 cleanDate();
	    			 $('#dg').datagrid('reload');	    			 
		    	 }else if(msg == "repeat"){
		           	 $.messager.alert('消息', "该驾驶员已存在,请修改后保存!");
		         }else{
		        	 document.write(msg);//异常捕获跳转
		         }	  
		    } 
		 });
	}
	
	//删除驾驶员
	function delDriverDate(id){
		$.ajax({
			type : 'post',
			url :  '${basePath}/bus/carDriverArchives/delete.do',
			data : "id="+id,
			dataType:"json",
			success : function(msg) {
				$.each(msg,function(i,n){
            		if(n.message == "success"){
            			$.messager.alert("消息", "删除成功！");
            			$('#dg').datagrid('reload');	
            		}else{
            			$.messager.alert('消息', n.errMsg);
            		}
               });
			}
		});
	}
	
	//清空驾驶员信息
	function cleanDate(){
		$("#passportNo").textbox('setValue','');
		$("#name").textbox('setValue','');
		$("#phone").textbox('setValue','');
		$("#address").textbox('setValue','');
	}
	
</script>